import {BrowserWindow} from "electron";
import path from "path";
import devtoolsInstaller, {VUEJS3_DEVTOOLS} from 'electron-devtools-installer'

class MainController {
  constructor () {
    this.init()
  }

  init () {
    this.Window = new BrowserWindow({
      width: 400,
      height: 600,
      show: false,
      titleBarStyle: 'hiddenInset',
      autoHideMenuBar: true,
      useContentSize: true,
      icon: path.join(__dirname, './icons/icon'),
      webPreferences: {
        contextIsolation: true,
        nativeWindowOpen: true,
        // More info: /quasar-cli/developing-electron-apps/electron-preload-script
        preload: path.resolve(__dirname, process.env.QUASAR_ELECTRON_PRELOAD)
      }
    })
    this.Window.loadURL(process.env.APP_URL)
    this.Window.webContents.on('dom-ready', () => {
      this.show()
    })

    this.Window.on('close', () => {
        this.Window = null
    })
  }

  show () {
    this.Window.show()
    this.Window.focus()
  }

  toggle () {
    if (this.Window.isFocused()) {
      this.Window.hide()
    } else {
      this.show()
    }
  }
}

export default MainController
